package com.blockmeta.bbs.minemodule.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.blockmeta.bbs.baselibrary.utils.FormatUtil;
import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.minemodule.R;
import com.blockmeta.bbs.minemodule.pojo.IMyActiveListPOJO;
import com.blockmeta.bbs.minemodule.pojo.MyActiveListPOJO;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author AirThor
 * @date 2019/12/12.
 */
public class MyActiveListMultiAdapter extends BaseMultiItemQuickAdapter<IMyActiveListPOJO, BaseViewHolder> {
    private OnAcitiveItemClickListener mOnAcitiveItemClickListener;

    public void setOnAcitiveItemClickListener(OnAcitiveItemClickListener onAcitiveItemClickListener) {
        mOnAcitiveItemClickListener = onAcitiveItemClickListener;
    }

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MyActiveListMultiAdapter(List<IMyActiveListPOJO> data) {
        super(data);
        addItemType(MyActiveListPOJO.ListBean.NORMAL, R.layout.item_my_active_list);
    }

    @Override
    protected void convert(BaseViewHolder helper, IMyActiveListPOJO item) {
        int viewType = helper.getItemViewType();
        initNormal(helper,item);
    }

    private void initNormal(BaseViewHolder helper, final IMyActiveListPOJO item) {
        helper.setText(R.id.tv_title,item.getTitle());
        ImageView icon = helper.getView(R.id.iv_icon);
        LoadPicUtil.load(item.getAttachUrl(),icon);

        if (item.iSActiveOverdue()){
            helper.setGone(R.id.tv_date_out,true);
        }else {
            helper.setGone(R.id.tv_date_out,false);
        }

        String time=FormatUtil.getTimetoHMS(item.getStartTimeFrom()*1000,"yyyy-MM-dd HH:mm");

        helper.setText(R.id.tv_date,time);

        helper.setText(R.id.tv_address,item.getPlace());
        if (TextUtils.isEmpty(item.getTicketName())){
            helper.setGone(R.id.tv_ticket_name,false);
        }else {
            helper.setGone(R.id.tv_ticket_name,true);
            helper.setText(R.id.tv_ticket_name, item.getTicketName());
        }

        final View main = helper.getView(R.id.item_click);
        if (mOnAcitiveItemClickListener==null){
            return;
        }
        main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnAcitiveItemClickListener.onActiveItemClickListener(item);
            }
        });
    }

    public interface OnAcitiveItemClickListener{
        void onActiveItemClickListener(IMyActiveListPOJO item);
    }
}
